package xyz.zhzby.cyzx.cms.controller;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import xyz.zhzby.cyzx.cms.dto.response.TagResponse;
import xyz.zhzby.cyzx.cms.service.ITagService;
import xyz.zhzby.cyzx.servicebase.domain.RestResponse;

import java.util.List;

/**
 * @author zby
 * @date 2021/12/11
 */
@RestController
@RequestMapping("/cms/tag")
@ApiModel("文章标签API")
public class TagController {

    @Autowired
    private ITagService tagService;

    @ApiOperation("创建文章标签")
    @PostMapping("")
    public RestResponse<String> createTag(@RequestParam("tagName") String tagName) {
        return tagService.createTag(tagName);
    }

    @ApiOperation("查看所有文章标签（不会很多，不用分页）")
    @GetMapping("/list")
    public RestResponse<List<TagResponse>> getAllTags() {
        return tagService.getAllTags();
    }

    @ApiOperation("删除标签")
    @DeleteMapping("/{tagId}")
    public RestResponse<String> deleteTag(@PathVariable("tagId") Long tagId) {
        tagService.removeById(tagId);
        return RestResponse.success("删除成功");
    }

}
